package com.org.cloud.lg.controller;

import com.org.cloud.lg.api.RoleMenuService;
import com.org.cloud.lg.dto.MenuDto;
import com.org.cloud.lg.dto.RoleMenuDto;
import com.org.cloud.lg.model.BaseController;
import com.org.cloud.lg.utils.ApiResult;
import com.org.cloud.lg.utils.Checker;
import com.org.cloud.lg.utils.Tree;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 角色与菜单对应关系 前端控制器
 * </p>
 *
 * @author dl
 * @since 2018-03-23
 */
@RestController
@RequestMapping("/role/roleMenu")
public class RoleMenuController extends BaseController<RoleMenuService> {
	@Autowired
	RoleMenuService roleMenuService;

	@RequestMapping("/selectTreeMenuByRole")
	public Tree<MenuDto> selectTreeMenuByRole(@RequestParam String roleId){
		Tree<MenuDto> menus=roleMenuService.selectTreeMenuByUser(roleId,getUserId());
		return menus;
	}
	
	@RequestMapping("/assignMenu")
	public ApiResult assignMenu(@RequestBody RoleMenuDto roleMenuDto){
		if(Checker.BeEmpty(roleMenuDto.getOnCheckKeys())||Checker.BeBlank(roleMenuDto.getRoleId())){
			return ApiResult.result("参数异常!",-1);
		}
		boolean f=roleMenuService.assignMenu(roleMenuDto);
		if(f){
			return ApiResult.result();
		}
		else
		return ApiResult.result("操作失败",-1);
	}
}
